package org.example.computerdesign.util;

import cn.hutool.http.Header;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 本类用于与python程序通信
 * @author 朱文权
 * */
public class PythonUtil {
    private static String url="http://127.0.0.1:5000";
    public static String get(String api,Map<String,Object> params){
        String uriApi=url+api;
        return HttpUtil.get(uriApi,params);
    }
    public static String post(String api,String json){
        Map<String,String> headers=new HashMap<>();
        headers.put("Content-Type","application/json");
        String urlApi=url+api;
        return HttpUtil.createPost(urlApi)
                .addHeaders(headers)
                .body(json)
                .execute()
                .body();
    }
}
